<?
function newimg($image) {
	list($width_orig, $height_orig, $imagetype) = getimagesize($image);
	switch ($imagetype) {
        case 1: $im = imagecreatefromgif($image); break;
        case 2: $im = imagecreatefromjpeg($image);  break;
        case 3: $im = imagecreatefrompng($image); break;
        default:  trigger_error('Unsupported filetype!', E_USER_WARNING);  break;
    }
	$newImg = imagecreatetruecolor($width_orig, $height_orig);
	if(($imagetype == 1) OR ($imagetype==3)) {
        imagealphablending($newImg, false);
        imagesavealpha($newImg,true);
        $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
        imagefilledrectangle($newImg, 0, 0, $width_orig, $height_orig, $transparent);
    }
    imagecopyresampled($newImg, $im, 0, 0, 0, 0, $width_orig, $height_orig, $width_orig, $height_orig);
   
	switch ($imagetype) {
        case 1: header('Content-Type: image/gif'); imagegif($newImg); break;
        case 2: header('Content-Type: image/jpeg'); imagejpeg($newImg);  break;
        case 3: header('Content-Type: image/png'); imagepng($newImg); break;
        default:  trigger_error('Failed resize image!', E_USER_WARNING);  break;
    }
}
//Urls
$urlPath = htmlspecialchars($_SERVER['REQUEST_URI']);// nao alterar

$url_array = explode("/",$urlPath);
//verifica se esta acessando via url alternativa ex: http://localhost/usuario
htmlspecialchars("array_slice($url_array, 1)", ENT_QUOTES);
$url = array_slice($url_array, 1);

$baseimg = 'http://brunoramos.eti.br/admin/';
$img_tipo = $url[1];
$img_name = $url[2];
switch($img_tipo) {
	case "cont": newimg($baseimg."conteudos/images/".$img_name); break;
	case "cat": newimg($baseimg."categorias/images/".$img_name); break;
}


?> 